/********************************************************************
	Rhapsody	: 7.5 
	Login		: KBE
	Component	: DefaultComponent 
	Configuration 	: ClientCodeConfig
	Model Element	: PatientEvent
//!	Generated Date	: Sun, 23, Sep 2012  
	File Path	: DefaultComponent\ClientCodeConfig\PatientEvent.cpp
*********************************************************************/

//## auto_generated
#include "PatientEvent.h"
//## auto_generated
#include "Reactor.h"
//## package Default

//## class PatientEvent
PatientEvent::PatientEvent(Reactor * reactor, HANDLE h) {
    //#[ operation PatientEvent(Reactor *,HANDLE)
    handle = h;
    itsReactor = reactor;
    strcpy(buffer_, "empty");
    //#]
}

PatientEvent::PatientEvent() {
}

PatientEvent::PatientEvent(Reactor * reactor, SOCK_Stream* stream) {
    //#[ operation PatientEvent(Reactor *,SOCK_Stream*)
    //#[ operation LogEvent(Reactor*,SOCK_Stream)
    setPeer_stream_(stream);
    handle = (HANDLE)stream->get_handle();
    itsReactor = reactor;
    itsReactor->registerHandler(*this, READ_EVENT);
    //#]
}

PatientEvent::~PatientEvent() {
}

void PatientEvent::handleEvent(HANDLE h, Event_Type& et) {
    //#[ operation handleEvent(HANDLE,Event_Type)
    if (et == type) {
    	int n = getPeer_stream_()->recv_n(buffer_, sizeof(buffer_), 0);
    	if (n > 0) { 
    		PatientAction();
    	}
    	else 
    	{
    		itsReactor->removeHandler(*this, type);
    		delete this; // Deallocate ourselves
    	}
    }
    //#]
}

void PatientEvent::PatientAction() {
    //#[ operation PatientAction()
    char temp[1000];
	printf("Patient: %s\n", buffer_);
	sprintf(temp, "Server: %s\n", buffer_);
	getPeer_stream_()->send_n(temp, 200, 0);
    //#]
}

char PatientEvent::getBuffer_(int i1) const {
    return buffer_[i1];
}

void PatientEvent::setBuffer_(int i1, char p_buffer_) {
    buffer_[i1] = p_buffer_;
}

/*********************************************************************
	File Path	: DefaultComponent\ClientCodeConfig\PatientEvent.cpp
*********************************************************************/
